﻿using UnityEngine;
using System.Collections;

public class ShipScript : MonoBehaviour {

	public int health;
	public GameObject explosion;
	
	// Update is called once per frame
	void OnTriggerEnter2D(Collider2D other) {
		//Excute if the object tag was equal to one of these
		if(other.tag == "Asteroid")
		{
			//Check the Health if greater than 0
			if(health > 0)
			{
				health -= other.GetComponent<StrengthScript>().strength;

				if(health <= 0)
				{
					HighScore.gameover = true;
					
					Annihilate(gameObject);
				}
			}
		}
	}

	void Annihilate(GameObject o) {
		foreach (Transform t in o.GetComponentsInChildren<Transform>()) {
			Instantiate (explosion, t.transform.position, t.transform.rotation); //Instantiate explosion
		}
		Invoke( "deadDieDeath" , 0.2f);
	}

	void deadDieDeath(){
		gameObject.transform.position = new Vector3(-1000,-550,0);
	}
}